
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>stat --- 解析 stat() 结果 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="filecmp --- 文件及目录的比较" href="filecmp.html" />
    <link rel="prev" title="fileinput --- 迭代来自多个输入流的行" href="fileinput.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/stat.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="filecmp.html" title="filecmp --- 文件及目录的比较"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="fileinput.html" title="fileinput --- 迭代来自多个输入流的行"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="filesys.html" accesskey="U">文件和目录访问</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-stat">
<span id="stat-interpreting-stat-results"></span><h1><a class="reference internal" href="#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> --- 解析 <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a> 结果<a class="headerlink" href="#module-stat" title="永久链接至标题">¶</a></h1>
<p><strong>源代码：</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/stat.py">Lib/stat.py</a></p>
<hr class="docutils" />
<p><a class="reference internal" href="#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> 模块定义了一些用于解析 <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>, <a class="reference internal" href="os.html#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fstat()</span></code></a> 和 <a class="reference internal" href="os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> (如果它们存在) 输出结果的常量和函数。 有关 <code class="xref c c-func docutils literal notranslate"><span class="pre">stat()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">fstat()</span></code> 和 <code class="xref c c-func docutils literal notranslate"><span class="pre">lstat()</span></code> 调用的完整细节，请参阅你的系统文档。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.4 版更改: </span>stat 模块是通过 C 实现来支持的。</p>
</div>
<p><a class="reference internal" href="#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> 模块定义了以下函数来检测特定文件类型：</p>
<dl class="function">
<dt id="stat.S_ISDIR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISDIR</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISDIR" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个目录则返回非零值。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISCHR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISCHR</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISCHR" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个字符专属的设备文件则返回非零值。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISBLK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISBLK</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISBLK" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个块特殊设备文件则返回非零值。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISREG">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISREG</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISREG" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个常规文件则返回非零值。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISFIFO">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISFIFO</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISFIFO" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个 FIFO (命名管道) 则返回非零值。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISLNK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISLNK</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISLNK" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个符号链接则返回非零值。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISSOCK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISSOCK</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISSOCK" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个套接字则返回非零值。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISDOOR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISDOOR</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISDOOR" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个门则返回非零值。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISPORT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISPORT</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISPORT" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个事件端口则返回非零值。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="stat.S_ISWHT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISWHT</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_ISWHT" title="永久链接至目标">¶</a></dt>
<dd><p>如果 mode 来自一个白输出则返回非零值。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>

<p>定义了两个附加函数用于对文件模式进行更一般化的操作：</p>
<dl class="function">
<dt id="stat.S_IMODE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IMODE</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_IMODE" title="永久链接至目标">¶</a></dt>
<dd><p>返回文件模式中可由 <a class="reference internal" href="os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chmod()</span></code></a> 进行设置的部分 --- 即文件的 permission 位，加上 sticky 位、set-group-id 以及 set-user-id 位（在支持这些部分的系统上）。</p>
</dd></dl>

<dl class="function">
<dt id="stat.S_IFMT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFMT</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.S_IFMT" title="永久链接至目标">¶</a></dt>
<dd><p>返回文件模式中描述文件类型的部分（供上面的 <code class="xref py py-func docutils literal notranslate"><span class="pre">S_IS*()</span></code> 函数使用）。</p>
</dd></dl>

<p>通常，你应当使用 <code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.is*()</span></code> 函数来检测文件的类型；这里提供的函数则适用于当你要对同一文件执行多项检测并且希望避免每项检测的 <code class="xref c c-func docutils literal notranslate"><span class="pre">stat()</span></code> 系统调用开销的情况。 这些函数也适用于检测有关未被 <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> 处理的信息，例如检测块和字符设备等。</p>
<p>示例:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">stat</span> <span class="kn">import</span> <span class="o">*</span>

<span class="k">def</span> <span class="nf">walktree</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">callback</span><span class="p">):</span>
    <span class="sd">&#39;&#39;&#39;recursively descend the directory tree rooted at top,</span>
<span class="sd">       calling the callback function for each regular file&#39;&#39;&#39;</span>

    <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">top</span><span class="p">):</span>
        <span class="n">pathname</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
        <span class="n">mode</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">pathname</span><span class="p">)</span><span class="o">.</span><span class="n">st_mode</span>
        <span class="k">if</span> <span class="n">S_ISDIR</span><span class="p">(</span><span class="n">mode</span><span class="p">):</span>
            <span class="c1"># It&#39;s a directory, recurse into it</span>
            <span class="n">walktree</span><span class="p">(</span><span class="n">pathname</span><span class="p">,</span> <span class="n">callback</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">S_ISREG</span><span class="p">(</span><span class="n">mode</span><span class="p">):</span>
            <span class="c1"># It&#39;s a file, call the callback function</span>
            <span class="n">callback</span><span class="p">(</span><span class="n">pathname</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Unknown file type, print a message</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Skipping </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">pathname</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">visitfile</span><span class="p">(</span><span class="n">file</span><span class="p">):</span>
    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;visiting&#39;</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">walktree</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">visitfile</span><span class="p">)</span>
</pre></div>
</div>
<p>另外还提供了一个附加的辅助函数用来将文件模式转换为人类易读的字符串：</p>
<dl class="function">
<dt id="stat.filemode">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">filemode</code><span class="sig-paren">(</span><em class="sig-param">mode</em><span class="sig-paren">)</span><a class="headerlink" href="#stat.filemode" title="永久链接至目标">¶</a></dt>
<dd><p>将文件模式转换为 '-rwxrwxrwx' 形式的字符串。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.3 新版功能.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.4 版更改: </span>此函数支持 <a class="reference internal" href="#stat.S_IFDOOR" title="stat.S_IFDOOR"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IFDOOR</span></code></a>, <a class="reference internal" href="#stat.S_IFPORT" title="stat.S_IFPORT"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IFPORT</span></code></a> and <a class="reference internal" href="#stat.S_IFWHT" title="stat.S_IFWHT"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IFWHT</span></code></a>。</p>
</div>
</dd></dl>

<p>以下所有变量是一些简单的符号索引，用于访问 <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>, <a class="reference internal" href="os.html#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fstat()</span></code></a> 或 <a class="reference internal" href="os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> 所返回的 10 条目元组。</p>
<dl class="data">
<dt id="stat.ST_MODE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_MODE</code><a class="headerlink" href="#stat.ST_MODE" title="永久链接至目标">¶</a></dt>
<dd><p>inode保护模式。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_INO">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_INO</code><a class="headerlink" href="#stat.ST_INO" title="永久链接至目标">¶</a></dt>
<dd><p>Inode 号</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_DEV">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_DEV</code><a class="headerlink" href="#stat.ST_DEV" title="永久链接至目标">¶</a></dt>
<dd><p>Inode 所在的设备。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_NLINK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_NLINK</code><a class="headerlink" href="#stat.ST_NLINK" title="永久链接至目标">¶</a></dt>
<dd><p>Inode 拥有的链接数量。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_UID">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_UID</code><a class="headerlink" href="#stat.ST_UID" title="永久链接至目标">¶</a></dt>
<dd><p>所有者的用户ID。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_GID">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_GID</code><a class="headerlink" href="#stat.ST_GID" title="永久链接至目标">¶</a></dt>
<dd><p>所有者的用户组ID。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_SIZE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_SIZE</code><a class="headerlink" href="#stat.ST_SIZE" title="永久链接至目标">¶</a></dt>
<dd><p>以字节为单位的普通文件大小；对于某些特殊文件的预期数据量。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_ATIME">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_ATIME</code><a class="headerlink" href="#stat.ST_ATIME" title="永久链接至目标">¶</a></dt>
<dd><p>上次访问的时间。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_MTIME">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_MTIME</code><a class="headerlink" href="#stat.ST_MTIME" title="永久链接至目标">¶</a></dt>
<dd><p>上次修改的时间。</p>
</dd></dl>

<dl class="data">
<dt id="stat.ST_CTIME">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">ST_CTIME</code><a class="headerlink" href="#stat.ST_CTIME" title="永久链接至目标">¶</a></dt>
<dd><p>操作系统所报告的 &quot;ctime&quot;。 在某些系统上（例如 Unix）是元数据的最后修改时间，而在其他系统上（例如 Windows）则是创建时间（请参阅系统平台的文档了解相关细节）。</p>
</dd></dl>

<p>对于“文件大小”的解析可因文件类型的不同而变化。 对于普通文件就是文件的字节数。 对于大部分种类的 Unix（特别包括 Linux）的 FIFO 和套接字来说，“大小”则是指在调用 <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>, <a class="reference internal" href="os.html#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fstat()</span></code></a> 或 <a class="reference internal" href="os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> 时等待读取的字节数；这在某些时候很有用处，特别是在一个非阻塞的打开后轮询这些特殊文件中的一个时。 其他字符和块设备的文件大小字段的含义还会有更多变化，具体取决于底层系统调用的实现方式。</p>
<p>以下变量定义了在 <a class="reference internal" href="#stat.ST_MODE" title="stat.ST_MODE"><code class="xref py py-data docutils literal notranslate"><span class="pre">ST_MODE</span></code></a> 字段中使用的旗标。</p>
<p>使用上面的函数会比使用第一组旗标更容易移植：</p>
<dl class="data">
<dt id="stat.S_IFSOCK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFSOCK</code><a class="headerlink" href="#stat.S_IFSOCK" title="永久链接至目标">¶</a></dt>
<dd><p>套接字</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFLNK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFLNK</code><a class="headerlink" href="#stat.S_IFLNK" title="永久链接至目标">¶</a></dt>
<dd><p>符号链接。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFREG">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFREG</code><a class="headerlink" href="#stat.S_IFREG" title="永久链接至目标">¶</a></dt>
<dd><p>普通文件。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFBLK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFBLK</code><a class="headerlink" href="#stat.S_IFBLK" title="永久链接至目标">¶</a></dt>
<dd><p>块设备</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFDIR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFDIR</code><a class="headerlink" href="#stat.S_IFDIR" title="永久链接至目标">¶</a></dt>
<dd><p>目录</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFCHR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFCHR</code><a class="headerlink" href="#stat.S_IFCHR" title="永久链接至目标">¶</a></dt>
<dd><p>字符设备。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFIFO">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFIFO</code><a class="headerlink" href="#stat.S_IFIFO" title="永久链接至目标">¶</a></dt>
<dd><p>先进先出</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFDOOR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFDOOR</code><a class="headerlink" href="#stat.S_IFDOOR" title="永久链接至目标">¶</a></dt>
<dd><p>门</p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFPORT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFPORT</code><a class="headerlink" href="#stat.S_IFPORT" title="永久链接至目标">¶</a></dt>
<dd><p>事件端口。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="stat.S_IFWHT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IFWHT</code><a class="headerlink" href="#stat.S_IFWHT" title="永久链接至目标">¶</a></dt>
<dd><p>白输出。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.4 新版功能.</span></p>
</div>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">注解</p>
<p><a class="reference internal" href="#stat.S_IFDOOR" title="stat.S_IFDOOR"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IFDOOR</span></code></a>, <a class="reference internal" href="#stat.S_IFPORT" title="stat.S_IFPORT"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IFPORT</span></code></a> or <a class="reference internal" href="#stat.S_IFWHT" title="stat.S_IFWHT"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IFWHT</span></code></a> 等文件类型在不受系统平台支持时会被定义为 0。</p>
</div>
<p>以下旗标还可以 <a class="reference internal" href="os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chmod()</span></code></a> 的在 <em>mode</em> 参数中使用：</p>
<dl class="data">
<dt id="stat.S_ISUID">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISUID</code><a class="headerlink" href="#stat.S_ISUID" title="永久链接至目标">¶</a></dt>
<dd><p>设置UID位。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_ISGID">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISGID</code><a class="headerlink" href="#stat.S_ISGID" title="永久链接至目标">¶</a></dt>
<dd><p>设置分组 ID 位。 这个位有几种特殊用途。 对于目录它表示该目录将使用 BSD 语义：在其中创建的文件将从目录继承其分组 ID，而不是从创建进程的有效分组 ID 继承，并且在其中创建的目录也将设置 <a class="reference internal" href="#stat.S_ISGID" title="stat.S_ISGID"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_ISGID</span></code></a> 位。 对于没有设置分组执行位 (<a class="reference internal" href="#stat.S_IXGRP" title="stat.S_IXGRP"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IXGRP</span></code></a>) 的文件，设置分组 ID 位表示强制性文件/记录锁定 (另请参见 <a class="reference internal" href="#stat.S_ENFMT" title="stat.S_ENFMT"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_ENFMT</span></code></a>)。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_ISVTX">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ISVTX</code><a class="headerlink" href="#stat.S_ISVTX" title="永久链接至目标">¶</a></dt>
<dd><p>固定位。 当对目录设置该位时则意味着此目录中的文件只能由文件所有者、目录所有者或特权进程来重命名或删除。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IRWXU">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IRWXU</code><a class="headerlink" href="#stat.S_IRWXU" title="永久链接至目标">¶</a></dt>
<dd><p>文件所有者权限的掩码。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IRUSR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IRUSR</code><a class="headerlink" href="#stat.S_IRUSR" title="永久链接至目标">¶</a></dt>
<dd><p>所有者具有读取权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IWUSR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IWUSR</code><a class="headerlink" href="#stat.S_IWUSR" title="永久链接至目标">¶</a></dt>
<dd><p>所有者具有写入权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IXUSR">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IXUSR</code><a class="headerlink" href="#stat.S_IXUSR" title="永久链接至目标">¶</a></dt>
<dd><p>所有者具有执行权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IRWXG">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IRWXG</code><a class="headerlink" href="#stat.S_IRWXG" title="永久链接至目标">¶</a></dt>
<dd><p>组权限的掩码。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IRGRP">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IRGRP</code><a class="headerlink" href="#stat.S_IRGRP" title="永久链接至目标">¶</a></dt>
<dd><p>组具有读取权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IWGRP">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IWGRP</code><a class="headerlink" href="#stat.S_IWGRP" title="永久链接至目标">¶</a></dt>
<dd><p>组具有写入权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IXGRP">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IXGRP</code><a class="headerlink" href="#stat.S_IXGRP" title="永久链接至目标">¶</a></dt>
<dd><p>组具有执行权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IRWXO">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IRWXO</code><a class="headerlink" href="#stat.S_IRWXO" title="永久链接至目标">¶</a></dt>
<dd><p>其他人（不在组中）的权限掩码。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IROTH">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IROTH</code><a class="headerlink" href="#stat.S_IROTH" title="永久链接至目标">¶</a></dt>
<dd><p>其他人具有读取权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IWOTH">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IWOTH</code><a class="headerlink" href="#stat.S_IWOTH" title="永久链接至目标">¶</a></dt>
<dd><p>其他人具有写入权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IXOTH">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IXOTH</code><a class="headerlink" href="#stat.S_IXOTH" title="永久链接至目标">¶</a></dt>
<dd><p>其他人具有执行权限。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_ENFMT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_ENFMT</code><a class="headerlink" href="#stat.S_ENFMT" title="永久链接至目标">¶</a></dt>
<dd><p>System V 执行文件锁定。 此旗标是与 <a class="reference internal" href="#stat.S_ISGID" title="stat.S_ISGID"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_ISGID</span></code></a> 共享的：文件/记录锁定会针对未设置分组执行位 (<a class="reference internal" href="#stat.S_IXGRP" title="stat.S_IXGRP"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IXGRP</span></code></a>) 的文件强制执行。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IREAD">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IREAD</code><a class="headerlink" href="#stat.S_IREAD" title="永久链接至目标">¶</a></dt>
<dd><p>Unix V7 中 <a class="reference internal" href="#stat.S_IRUSR" title="stat.S_IRUSR"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IRUSR</span></code></a> 的同义词。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IWRITE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IWRITE</code><a class="headerlink" href="#stat.S_IWRITE" title="永久链接至目标">¶</a></dt>
<dd><p>Unix V7 中 <a class="reference internal" href="#stat.S_IWUSR" title="stat.S_IWUSR"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IWUSR</span></code></a> 的同义词。</p>
</dd></dl>

<dl class="data">
<dt id="stat.S_IEXEC">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">S_IEXEC</code><a class="headerlink" href="#stat.S_IEXEC" title="永久链接至目标">¶</a></dt>
<dd><p>Unix V7 中 <a class="reference internal" href="#stat.S_IXUSR" title="stat.S_IXUSR"><code class="xref py py-data docutils literal notranslate"><span class="pre">S_IXUSR</span></code></a> 的同义词。</p>
</dd></dl>

<p>以下旗标可以在 <a class="reference internal" href="os.html#os.chflags" title="os.chflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chflags()</span></code></a> 的 <em>flags</em> 参数中使用：</p>
<dl class="data">
<dt id="stat.UF_NODUMP">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">UF_NODUMP</code><a class="headerlink" href="#stat.UF_NODUMP" title="永久链接至目标">¶</a></dt>
<dd><p>不要转储文件。</p>
</dd></dl>

<dl class="data">
<dt id="stat.UF_IMMUTABLE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">UF_IMMUTABLE</code><a class="headerlink" href="#stat.UF_IMMUTABLE" title="永久链接至目标">¶</a></dt>
<dd><p>文件不能更改。</p>
</dd></dl>

<dl class="data">
<dt id="stat.UF_APPEND">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">UF_APPEND</code><a class="headerlink" href="#stat.UF_APPEND" title="永久链接至目标">¶</a></dt>
<dd><p>文件只能附加到。</p>
</dd></dl>

<dl class="data">
<dt id="stat.UF_OPAQUE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">UF_OPAQUE</code><a class="headerlink" href="#stat.UF_OPAQUE" title="永久链接至目标">¶</a></dt>
<dd><p>当通过联合堆栈查看时，目录是不透明的。</p>
</dd></dl>

<dl class="data">
<dt id="stat.UF_NOUNLINK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">UF_NOUNLINK</code><a class="headerlink" href="#stat.UF_NOUNLINK" title="永久链接至目标">¶</a></dt>
<dd><p>文件不能重命名或删除。</p>
</dd></dl>

<dl class="data">
<dt id="stat.UF_COMPRESSED">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">UF_COMPRESSED</code><a class="headerlink" href="#stat.UF_COMPRESSED" title="永久链接至目标">¶</a></dt>
<dd><p>文件是压缩存储的（Mac OS X 10.6+）。</p>
</dd></dl>

<dl class="data">
<dt id="stat.UF_HIDDEN">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">UF_HIDDEN</code><a class="headerlink" href="#stat.UF_HIDDEN" title="永久链接至目标">¶</a></dt>
<dd><p>文件不能显示在GUI 中（Mac OS X 10.5+）。</p>
</dd></dl>

<dl class="data">
<dt id="stat.SF_ARCHIVED">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">SF_ARCHIVED</code><a class="headerlink" href="#stat.SF_ARCHIVED" title="永久链接至目标">¶</a></dt>
<dd><p>文件可能已存档。</p>
</dd></dl>

<dl class="data">
<dt id="stat.SF_IMMUTABLE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">SF_IMMUTABLE</code><a class="headerlink" href="#stat.SF_IMMUTABLE" title="永久链接至目标">¶</a></dt>
<dd><p>文件不能更改。</p>
</dd></dl>

<dl class="data">
<dt id="stat.SF_APPEND">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">SF_APPEND</code><a class="headerlink" href="#stat.SF_APPEND" title="永久链接至目标">¶</a></dt>
<dd><p>文件只能附加到。</p>
</dd></dl>

<dl class="data">
<dt id="stat.SF_NOUNLINK">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">SF_NOUNLINK</code><a class="headerlink" href="#stat.SF_NOUNLINK" title="永久链接至目标">¶</a></dt>
<dd><p>文件不能重命名或删除。</p>
</dd></dl>

<dl class="data">
<dt id="stat.SF_SNAPSHOT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">SF_SNAPSHOT</code><a class="headerlink" href="#stat.SF_SNAPSHOT" title="永久链接至目标">¶</a></dt>
<dd><p>文件有一个快照文件</p>
</dd></dl>

<p>请参阅 *BSD 或 Mac OS 系统的指南页 <em class="manpage">chflags(2)</em> 了解详情。</p>
<p>在 Windows 上，以下文件属性常量可用于检测 <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> 所返回的 <code class="docutils literal notranslate"><span class="pre">st_file_attributes</span></code> 成员中的位。 请参阅 <a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx">Windows API 文档</a> 了解有关这些常量含义的详情。</p>
<dl class="data">
<dt id="stat.FILE_ATTRIBUTE_ARCHIVE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_ARCHIVE</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_ARCHIVE" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_COMPRESSED">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_COMPRESSED</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_COMPRESSED" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_DEVICE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_DEVICE</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_DEVICE" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_DIRECTORY">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_DIRECTORY</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_DIRECTORY" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_ENCRYPTED">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_ENCRYPTED</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_ENCRYPTED" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_HIDDEN">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_HIDDEN</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_HIDDEN" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_INTEGRITY_STREAM">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_INTEGRITY_STREAM</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_INTEGRITY_STREAM" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_NORMAL">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_NORMAL</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_NORMAL" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_NOT_CONTENT_INDEXED</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_NO_SCRUB_DATA">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_NO_SCRUB_DATA</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_NO_SCRUB_DATA" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_OFFLINE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_OFFLINE</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_OFFLINE" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_READONLY">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_READONLY</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_READONLY" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_REPARSE_POINT">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_REPARSE_POINT</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_REPARSE_POINT" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_SPARSE_FILE">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_SPARSE_FILE</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_SPARSE_FILE" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_SYSTEM">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_SYSTEM</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_SYSTEM" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_TEMPORARY">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_TEMPORARY</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_TEMPORARY" title="永久链接至目标">¶</a></dt>
<dt id="stat.FILE_ATTRIBUTE_VIRTUAL">
<code class="sig-prename descclassname">stat.</code><code class="sig-name descname">FILE_ATTRIBUTE_VIRTUAL</code><a class="headerlink" href="#stat.FILE_ATTRIBUTE_VIRTUAL" title="永久链接至目标">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">3.5 新版功能.</span></p>
</div>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="fileinput.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fileinput</span></code> --- 迭代来自多个输入流的行</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="filecmp.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code> --- 文件及目录的比较</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/stat.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="filecmp.html" title="filecmp --- 文件及目录的比较"
             >下一页</a> |</li>
        <li class="right" >
          <a href="fileinput.html" title="fileinput --- 迭代来自多个输入流的行"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="filesys.html" >文件和目录访问</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>